# -*- coding: utf-8 -*-
"""
-------------------------------------------------
Project Name: luffcity study project
File Name: 线程练习.py
Author: kij
Create Date: 2021/3/19
-------------------------------------------------
"""
# 通过thread类来启动线程
# 同一进程内多个线程共享该进程地址空间 age可以在线程中被改变，进程的话不会改变全局age
from threading import Thread,currentThread,activeCount,active_count,enumerate
from multiprocessing import Process
age = 100
def my_thread(name):
	global age
	age = 10
	print('线程', currentThread().getName())


if __name__ == '__main__':
	my = Thread(target=my_thread, args=("1",))
	my.setName("子进程")
	# my = Process(target=my_thread, args=("1",))
	# my.setDaemon(True)
	my.start()
	my.join()
	currentThread().setName('主线程')
	print(activeCount())
	print(active_count())
	print('主线程', currentThread().getName())
	print('主线程', enumerate())

# 通过继承Thread类来启动线程

# from threading import Thread
#
#
# class MyThread(Thread):
# 	def __init__(self, name):
# 		super(MyThread, self).__init__()
#
# 		self.name = name
#
# 	def run(self):
# 		print('线程启动', self.name)
#
#
# if __name__ == "__main__":
# 	for item in range(10):
# 		thread1 = MyThread('线程一')
# 		thread1.start()
# 	print('主线程')
